//
//  NewsInsureanceViewController.m
//  CarUser
//
//  Created by 王森林 on 2019/1/18.
//  Copyright © 2019年 王森林. All rights reserved.
//

#import "NewsInsureanceViewController.h"
#import "CustomPickerView.h"
#import "UserRes.h"
#import "HomeArticleDetailViewController.h"
#import "CarInsuranceCalculatorViewController.h"
#define BTGBUTTON 1000
@interface NewsInsureanceViewController ()<UITextFieldDelegate>
@property (nonatomic, strong) UIScrollView *scroll;
@property  (nonatomic, strong) UIView *topView;
@property (nonatomic, strong) UIView *centerView;
@property (nonatomic, strong) UIView *downView;


@property (nonatomic, strong) UILabel *dateLabel;
@property (nonatomic, strong) UILabel *typeLabel;
@property (nonatomic, strong) UITextField *contantField;
@property (nonatomic, strong) UITextField *mobileField;
@property (nonatomic, strong) UITextField *cityField;
@property (nonatomic, strong) UITextField *cardnoField;
@end

@implementation NewsInsureanceViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title  =  @"保险服务";
    [self createUI];
    // Do any additional setup after loading the view.
}

//提交
- (void)handleSumbitAction:(id)sender
{
    
    //保存预约
    
    if ([CommonMethod isBlankString:self.dateLabel.text]) {
        [SVProgressHUD showErrorWithStatus:@"请选择预约日期"];
        return ;
    }
    
    if ([CommonMethod isBlankString:self.typeLabel.text]) {
        [SVProgressHUD showErrorWithStatus:@"请选择保险类型"];
        return ;
    }
    
    if ([CommonMethod isBlankString:self.mobileField.text]) {
        [SVProgressHUD showErrorWithStatus:@"请输入联系电话"];
        return ;
    }
    
    if ([CommonMethod isBlankString:self.contantField.text]) {
        [SVProgressHUD showErrorWithStatus:@"请输入联系人"];
        return ;
    }
    if ([CommonMethod isBlankString:self.cityField.text]) {
        [SVProgressHUD showErrorWithStatus:@"请输入城市"];
        return ;
    }
    if ([CommonMethod isBlankString:self.cardnoField.text]) {
        [SVProgressHUD showErrorWithStatus:@"请输入车牌号"];
        return ;
    }
    
    NSString *type = @"1";
    if ([self.typeLabel.text isEqualToString:@"新车保险"]) {
        type = @"1";
    }
    if ([self.typeLabel.text isEqualToString:@"续保服务"]) {
         type = @"2";
    }
    if ([self.typeLabel.text isEqualToString:@"三包服务"]) {
         type = @"3";
    }
    
    UserRes *user = [CommonMethod getUser];
    if (!user) {
        [[NSNotificationCenter defaultCenter]postNotificationName:NotificationCenterName_AlertLoginVC object:nil];
        return;
    }
    
    NSMutableDictionary *param = [[NSMutableDictionary alloc] initWithDictionary:@{
                                                                                   @"FKEY":[CommonMethod createMD5Key:@"TOKEN"],
                                                                                   @"TOKEN":user.TOKEN,
                                                                                   @"USERNAME":user.mobile,
                                                                                   @"YYLX00":type,
                                                                                   @"LXR000":self.contantField.text,
                                                                                   @"LXDH00":self.mobileField.text,
                                                                                   @"YYRQ00":self.dateLabel.text
                                                                                   
                                                                                   }];
    if (![CommonMethod isBlankString:self.cityField.text]) {
        [param setObject:self.cityField.text forKey:@"SZCS00"];
    }
    if ([CommonMethod isBlankString:self.cardnoField.text]) {
         [param setObject:self.cardnoField.text forKey:@"CP0000"];
    }

    
//    NSDictionary *params = @{
//                             @"FKEY":[CommonMethod createMD5Key:@"TOKEN"],
//                             @"TOKEN":user.TOKEN,
//                             @"USERNAME":user.mobile,
//                             @"YYLX00":type,
//                             @"LXR000":self.contantField.text,
//                             @"LXDH00":self.mobileField.text,
//                             @"YYRQ00":self.dateLabel.text,
//                             @"SZCS00":self.cityField.text,
//                             @"CP0000":self.cardnoField.text
//
//                             };
    
    dispatch_async(dispatch_get_main_queue(), ^{
        [SVProgressHUD showWithStatus:nil];
    });
    
    [[ZY_AfnNetManager shareInstance]postWithURL:Car_API_48 params:param md5Paraname:nil success:^(id  _Nullable response) {
        
        dispatch_async(dispatch_get_main_queue(), ^{
            [SVProgressHUD dismiss];
        });
        dispatch_async(dispatch_get_main_queue(), ^{
            [SVProgressHUD showInfoWithStatus:@"预约成功"];
            //                [SVProgressHUD dismissWithDelay:10];
        });
        
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            dispatch_async(dispatch_get_main_queue(), ^{
                [self.navigationController popViewControllerAnimated:YES];
            });
        });
        
        
   
    
//        NSDictionary *resultDict  = response;
//        self.imgsAry  = [resultDict objectForKey:@"list"];
//        NSIndexPath *indexPath=[NSIndexPath indexPathForRow:0 inSection:0];
//        [self.mainTableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
        
        
    } fail:^(NSError * _Nonnull error) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [SVProgressHUD showErrorWithStatus:error.localizedDescription];
        });
        
    }];
    
}

//预约时间点击
- (void)handleDateTapAction:(UIGestureRecognizer *)gesture
{
//    NSArray *ary = [self createTimeChoose];
    [CustomPickerView initWithFrame:CGRectZero withModeType:DatePicker andTitleLab:@"选择时间" componentAry:nil andHasChoose:nil andCallBack:^(id resutData) {
        NSLog(@"%@",resutData);
        
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        [formatter setDateFormat:@"YYYY-MM-dd"];
        NSString *currentTimeString = [formatter stringFromDate:resutData];
        self.dateLabel.text = currentTimeString;
    


    }];
    
    
}
//保险类型点击
- (void)handleTypeTapAction:(UIGestureRecognizer *)gesture
{
    [UIActionSheet showInView:self.view withTitle:@"选择保险类型" cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@[@"新车保险",@"续保服务",@"三包服务"] tapBlock:^(UIActionSheet * _Nonnull actionSheet, NSInteger buttonIndex) {
        NSLog(@"index%ld",buttonIndex);
        switch (buttonIndex) {
            case 0:
            {
                self.typeLabel.text = @"新车保险";
            }
                break;
            case 1:
            {
                  self.typeLabel.text = @"续保服务";
            }
                break;
            case 2:
            {
                  self.typeLabel.text = @"三包服务";
            }
                break;
                
            default:
//                 self.typeLabel.text = @"新车保险";
                break;
        }
       }];
    
}


- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
//        if ([_NameTextField isFirstResponder]) {
//                [_IDCardTextField becomeFirstResponder];
//            } else if([_IDCardTextField isFirstResponder]) {
//                    [_MobileTextField becomeFirstResponder];
//                }
    
    if ([self.contantField isFirstResponder]) {
        [self.mobileField becomeFirstResponder];
    } else if ([self.mobileField isFirstResponder]) {
           [self.cityField becomeFirstResponder];
        
    } else if ([self.cityField isFirstResponder]) {
           [self.cardnoField becomeFirstResponder];
    }
    
      return YES;
}
- (void)textFieldDidChange:(UITextField *)textField
{
    if (textField == self.mobileField) {
        if (textField.text.length > 11) {
            　UITextRange *markedRange = [textField markedTextRange];
            　if (markedRange) {
                return;
            }
            //Emoji占2个字符，如果是超出了半个Emoji，用15位置来截取会出现Emoji截为2半
            //超出最大长度的那个字符序列(Emoji算一个字符序列)的range
            NSRange range = [textField.text rangeOfComposedCharacterSequenceAtIndex:11];
            textField.text = [textField.text substringToIndex:range.location];
        }
    }
}
#pragma mark -保险计算器
- (void)insuranceCalculatorAction{
    CarInsuranceCalculatorViewController *push = [[CarInsuranceCalculatorViewController alloc]init];
    [self.navigationController pushViewController:push animated:YES];
}


- (void)createUI
{
    [self.view addSubview:self.scroll];
    self.scroll.frame = CGRectMake(0, 0, BOUNDWIDTH, BOUNDHEIGHT);
    [self.scroll addSubview:self.topView];
    self.topView.frame = CGRectMake(0, 0, BOUNDWIDTH, 100);
    
      [self createBtnWithImg:@"insureance1" withTitle:@"车险加保" withIndex:0];
      [self createBtnWithImg:@"insureance2" withTitle:@"保单查询" withIndex:1];
      [self createBtnWithImg:@"insureance3" withTitle:@"支付订单" withIndex:2];
      [self createBtnWithImg:@"insureance4" withTitle:@"违章查询" withIndex:3];
      [self createBtnWithImg:@"insureance5" withTitle:@"变更车牌" withIndex:4];
      [self createBtnWithImg:@"insureance6" withTitle:@"历史报价" withIndex:5];
    
    [self.scroll addSubview:self.centerView];
    self.centerView.frame  = CGRectMake(0, 110, BOUNDWIDTH, 355);
    [self createCenterView];
    
    [self.scroll addSubview:self.downView];
    self.downView.frame = CGRectMake(0, 420+55, BOUNDWIDTH, 400);
    [self  createDownView];
    
    self.scroll.contentSize = CGSizeMake(BOUNDWIDTH, 900+55);
    
}

- (void)createDownView
{
    //预约日期
    UIView *dateView =  [[UIView alloc] initWithFrame:CGRectMake(0, 20,BOUNDWIDTH , 40)];
    UITapGestureRecognizer *dateTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDateTapAction:)];
    [dateView addGestureRecognizer:dateTap];
    [self.downView addSubview:dateView];
    
    NSMutableAttributedString *datestr = [[NSMutableAttributedString alloc] initWithString:@"预约日期*"];
    [datestr addAttribute:NSForegroundColorAttributeName value:RGB(51, 51, 51) range:NSMakeRange(0,4)];
    [datestr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(4,1)];
    
    UILabel *dateText  = [[UILabel alloc] initWithFrame:CGRectMake(15, 10, 80, 20)];
    dateText.attributedText = datestr;
//    dateText.text  = @"预约日期*" ;
//    dateText.textColor = Common_TextLowColor;
    dateText.font = FONT_SIZE(14);
    [dateView addSubview:dateText];
    
     self.dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(110, 10, BOUNDWIDTH - 150, 20)];
     self.dateLabel.textColor  = RGB(51, 51, 51);
     self.dateLabel.textAlignment = NSTextAlignmentRight;
     self.dateLabel.font  = FONT_SIZE(14);
    [dateView addSubview: self.dateLabel];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"YYYY-MM-dd"];
    NSDate *datenow = [NSDate date];
    NSString *currentTimeString = [formatter stringFromDate:datenow];
    self.dateLabel.text = currentTimeString;
    
    
    UIImageView *arrowImageView = [[UIImageView alloc] initWithFrame:CGRectMake(BOUNDWIDTH - 23, 13, 8, 14)];
    arrowImageView.image = IMG(@"home_arrow");
    [dateView addSubview:arrowImageView];
    
    
    //保险类型
    UIView *typeView =  [[UIView alloc] initWithFrame:CGRectMake(0, 70,BOUNDWIDTH , 40)];
    UITapGestureRecognizer *typeTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTypeTapAction:)];
    [typeView addGestureRecognizer:typeTap];
    [self.downView addSubview:typeView];
    
    NSMutableAttributedString *typestr = [[NSMutableAttributedString alloc] initWithString:@"保险类型*"];
    [typestr addAttribute:NSForegroundColorAttributeName value:RGB(51, 51, 51) range:NSMakeRange(0,4)];
    [typestr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(4,1)];
    
    UILabel *typeText  = [[UILabel alloc] initWithFrame:CGRectMake(15, 10, 80, 20)];
    typeText.attributedText = typestr;
//    typeText.text  = @"保险类型*" ;
//    typeText.textColor = Common_TextLowColor;
    typeText.font = FONT_SIZE(14);
    [typeView addSubview:typeText];
    
    self.typeLabel = [[UILabel alloc] initWithFrame:CGRectMake(110, 10, BOUNDWIDTH - 150, 20)];
    self.typeLabel.textColor  = RGB(51, 51, 51);
    self.typeLabel.textAlignment = NSTextAlignmentRight;
    self.typeLabel.font  = FONT_SIZE(14);
    self.typeLabel.text = @"新车保险";
    [typeView addSubview:self.typeLabel];
    
    
    UIImageView *arrowImageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(BOUNDWIDTH - 23, 13, 8, 14)];
    arrowImageView1.image = IMG(@"home_arrow");
    [typeView addSubview:arrowImageView1];
    
     //联系人
    UIView *contantView  = [[UIView alloc] initWithFrame:CGRectMake(0, 120, BOUNDWIDTH, 40)];
    [self.downView addSubview:contantView];
    
    
    
    NSMutableAttributedString *contantstr = [[NSMutableAttributedString alloc] initWithString:@"联系人*"];
    [contantstr addAttribute:NSForegroundColorAttributeName value:RGB(51, 51, 51) range:NSMakeRange(0,3)];
    [contantstr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(3,1)];
    UILabel *contantText  = [[UILabel alloc] initWithFrame:CGRectMake(15, 10, 80, 20)];
    contantText.attributedText = contantstr;
//    contantText.text  = @"联系人*" ;
//    contantText.textColor = Common_TextLowColor;
    contantText.font = FONT_SIZE(14);
    [contantView addSubview:contantText];
    
    
    self.contantField  = [[UITextField alloc] initWithFrame:CGRectMake(115, 0, BOUNDWIDTH - 125, 40)];
    self.contantField.layer.cornerRadius  = 15;
    self.contantField.layer.masksToBounds = YES;
    self.contantField.backgroundColor =  self.view.backgroundColor;
    self.contantField.textAlignment = NSTextAlignmentLeft;
    [self.contantField setValue:[NSNumber numberWithInt:10] forKey:@"paddingLeft"];
    self.contantField.returnKeyType = UIReturnKeyNext;
    self.contantField.delegate = self;
    self.contantField.font = FONT_SIZE(14);
    [contantView addSubview:self.contantField];
  
    
    
    //联系电话
    UIView *mobileView  = [[UIView alloc] initWithFrame:CGRectMake(0, 170, BOUNDWIDTH, 40)];
    [self.downView addSubview:mobileView];
    
    
    NSMutableAttributedString *mobilestr = [[NSMutableAttributedString alloc] initWithString:@"联系电话*"];
    [mobilestr addAttribute:NSForegroundColorAttributeName value:RGB(51, 51, 51) range:NSMakeRange(0,4)];
    [mobilestr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(4,1)];
    
    UILabel *mobileText  = [[UILabel alloc] initWithFrame:CGRectMake(15, 10, 80, 20)];
    mobileText.attributedText = mobilestr;
//    mobileText.text  = @"联系电话*" ;
//    mobileText.textColor = Common_TextLowColor;
    mobileText.font = FONT_SIZE(14);
    [mobileView addSubview:mobileText];
    
    
    
    
    self.mobileField  = [[UITextField alloc] initWithFrame:CGRectMake(110, 0, BOUNDWIDTH - 125, 40)];
    self.mobileField.layer.cornerRadius  = 15;
    self.mobileField.layer.masksToBounds = YES;
    self.mobileField.backgroundColor =  self.view.backgroundColor;
    self.mobileField.textAlignment = NSTextAlignmentLeft;
      [self.mobileField setValue:[NSNumber numberWithInt:10] forKey:@"paddingLeft"];
    self.mobileField.returnKeyType = UIReturnKeyNext;
    self.mobileField.delegate = self;
    [self.mobileField addTarget:self action:@selector(textFieldDidChange:)
               forControlEvents:UIControlEventEditingChanged];
      self.mobileField.keyboardType = UIKeyboardTypeNumberPad;
    self.mobileField.font = FONT_SIZE(14);
    [mobileView addSubview:self.mobileField];
    
    
    
    //所在城市"
    UIView *cityView  = [[UIView alloc] initWithFrame:CGRectMake(0, 220, BOUNDWIDTH, 40)];
    [self.downView addSubview:cityView];
    
    
    NSMutableAttributedString *citystr = [[NSMutableAttributedString alloc] initWithString:@"所在城市*"];
    [citystr addAttribute:NSForegroundColorAttributeName value:RGB(51, 51, 51) range:NSMakeRange(0,4)];
    [citystr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(4,1)];
    
    
    UILabel *cityText  = [[UILabel alloc] initWithFrame:CGRectMake(15, 10, 80, 20)];
//    cityText.text  = @"所在城市" ;
//    cityText.textColor = RGB(51, 51, 51);
    cityText.attributedText = citystr;
    cityText.font = FONT_SIZE(14);
    [cityView addSubview:cityText];
    
    
    self.cityField  = [[UITextField alloc] initWithFrame:CGRectMake(110, 0, BOUNDWIDTH - 125, 40)];
     self.cityField.layer.cornerRadius  = 15;
     self.cityField.layer.masksToBounds = YES;
     self.cityField.backgroundColor =  self.view.backgroundColor;
    self.cityField.textAlignment = NSTextAlignmentLeft;
    [self.cityField setValue:[NSNumber numberWithInt:10] forKey:@"paddingLeft"];
    self.cityField.returnKeyType = UIReturnKeyNext;
    self.cityField.delegate = self;
    self.cityField.font = FONT_SIZE(14);
    [cityView addSubview: self.cityField];
    
    //车牌号
    UIView *cardnoView  = [[UIView alloc] initWithFrame:CGRectMake(0, 270, BOUNDWIDTH, 40)];
    [self.downView addSubview:cardnoView];
    
    
    NSMutableAttributedString *cardnostr = [[NSMutableAttributedString alloc] initWithString:@"车牌号*"];
    [cardnostr addAttribute:NSForegroundColorAttributeName value:RGB(51, 51, 51) range:NSMakeRange(0,3)];
    [cardnostr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(3,1)];
    
    
    UILabel *cardnoText  = [[UILabel alloc] initWithFrame:CGRectMake(15, 10, 80, 20)];
//    cardnoText.text  = @"车牌号" ;
//    cardnoText.textColor = RGB(51, 51, 51);
    cardnoText.attributedText = cardnostr;
    cardnoText.font = FONT_SIZE(14);
    [cardnoView addSubview:cardnoText];
    
    
    self.cardnoField  = [[UITextField alloc] initWithFrame:CGRectMake(110, 0, BOUNDWIDTH - 125, 40)];
    self.cardnoField.layer.cornerRadius  = 15;
    self.cardnoField.layer.masksToBounds = YES;
    self.cardnoField.backgroundColor =  self.view.backgroundColor;
     self.cardnoField.textAlignment = NSTextAlignmentLeft;
        [self.cardnoField setValue:[NSNumber numberWithInt:10] forKey:@"paddingLeft"];
    self.cardnoField.returnKeyType = UIReturnKeyNext;
    self.cardnoField.delegate = self;
    self.cardnoField.font = FONT_SIZE(14);
    [cardnoView addSubview:self.cardnoField];
    
    
    
    UIButton  *sumbitBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    sumbitBtn.frame = CGRectMake(15, 330, BOUNDWIDTH - 30, 45);
    [sumbitBtn setTitle:@"提交" forState:UIControlStateNormal];
    sumbitBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    sumbitBtn.backgroundColor = RGB(254, 218, 60);
    sumbitBtn.layer.cornerRadius = 22;
    sumbitBtn.layer.masksToBounds = YES;
    [sumbitBtn setTitleColor:Common_TextColor forState:UIControlStateNormal];
    [sumbitBtn addTarget:self action:@selector(handleSumbitAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.downView addSubview:sumbitBtn];
    
    
    
}

- (void)createCenterView
{
    
    
    UIButton  *serviceBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    serviceBtn.frame = CGRectMake(15, 10, BOUNDWIDTH - 30, 45);
    [serviceBtn setTitle:@"保险计算器" forState:UIControlStateNormal];
    serviceBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    serviceBtn.backgroundColor = RGB(254, 218, 60);
    serviceBtn.layer.cornerRadius = 22;
    serviceBtn.layer.masksToBounds = YES;
    [serviceBtn setTitleColor:Common_TextColor forState:UIControlStateNormal];
    [serviceBtn addTarget:self action:@selector(insuranceCalculatorAction) forControlEvents:UIControlEventTouchUpInside];
    [self.centerView addSubview:serviceBtn];
    
    
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 65, BOUNDWIDTH, 18)];
    titleLabel.text = @"保险服务";
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.font = FONT_SIZE(17);
    titleLabel.textColor = Common_TextColor;
    [self.centerView addSubview:titleLabel];
    
    UILabel *smallLabel  =  [[UILabel alloc]initWithFrame:CGRectMake(BOUNDWIDTH/2-50, 90, 100, 15)];
    smallLabel.text = @"值得信赖";
    smallLabel.textAlignment = NSTextAlignmentCenter;
    smallLabel.font = FONT_SIZE(15);
    smallLabel.textColor = Common_TextColor;
    [self.centerView addSubview:smallLabel];
    
    UILabel *leftLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 90+15/2, BOUNDWIDTH/2-50,0.5)];
    leftLabel.backgroundColor = Common_SepeColor;
    [self.centerView addSubview:leftLabel];
    
    UILabel *rightLabel = [[UILabel alloc] initWithFrame:CGRectMake( BOUNDWIDTH/2+50, 90+15/2, BOUNDWIDTH/2-50,0.5)];
    rightLabel.backgroundColor = Common_SepeColor;
    [self.centerView addSubview:rightLabel];
    
    UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 115, BOUNDWIDTH, 100)];
    imageView1.image = IMG(@"insureance7");
    [self.centerView addSubview:imageView1];
    
    
    UILabel *titleLabel1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 235, BOUNDWIDTH, 18)];
    titleLabel1.text = @"快速购买 安心理赔 ";
    titleLabel1.textAlignment = NSTextAlignmentCenter;
    titleLabel1.font = FONT_SIZE(17);
    titleLabel1.textColor = Common_TextColor;
    [self.centerView addSubview:titleLabel1];
    
    
    UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 270, BOUNDWIDTH, 70)];
    imageView2.image = IMG(@"insureance8");
    [self.centerView addSubview:imageView2];
    
}

- (void)handleBtnAction:(id)sender
{
    
    UIButton *btn = sender;
    NSInteger tag = btn.tag - BTGBUTTON;
    switch (tag) {
        case 0:
        {
            HomeArticleDetailViewController *controller  = [[HomeArticleDetailViewController alloc] init];
            controller.article_id = @"98032c7940154980a7b863e36b3dc4dc";
            controller.title = @"车险加保详情";
            [self.navigationController pushViewController:controller animated:YES];
        }
            break;
        case 1:
        {
            HomeArticleDetailViewController *controller  = [[HomeArticleDetailViewController alloc] init];
            controller.article_id = @"46aed86ae48d47e79263d4ec4598d0ea";
            controller.title = @"保单查询详情";
            [self.navigationController pushViewController:controller animated:YES];
        }
            break;
        case 2:
        {
            HomeArticleDetailViewController *controller  = [[HomeArticleDetailViewController alloc] init];
            controller.article_id = @"ca456e5485f848ae91939c9f4712b16b";
            controller.title = @"支付订单详情";
            [self.navigationController pushViewController:controller animated:YES];
        }
            break;
        case 3:
        {
            HomeArticleDetailViewController *controller  = [[HomeArticleDetailViewController alloc] init];
            controller.article_id = @"f8a6309c468541df8f62eb464c36b196 ";
            controller.title = @"违章查询详情";
            [self.navigationController pushViewController:controller animated:YES];
        }
            break;
        case 4:
        {
            HomeArticleDetailViewController *controller  = [[HomeArticleDetailViewController alloc] init];
            controller.article_id = @"2e6636f2e1254b7eb8e6f09e48ebc094";
            controller.title = @"变更车牌详情";
            [self.navigationController pushViewController:controller animated:YES];
        }
            break;
        case 5:
        {
            HomeArticleDetailViewController *controller  = [[HomeArticleDetailViewController alloc] init];
            controller.article_id = @"41181b204a0640b391dfbc1fe33baa8b";
            controller.title = @"历史报价详情";
            [self.navigationController pushViewController:controller animated:YES];
        }
            break;
            
        default:
            break;
    }
   
    
}

-  (void )createBtnWithImg:(NSString *)imgName withTitle:(NSString *)title withIndex:(NSInteger)index
{
    UIImage *image = IMG(imgName);
    //    float marX = 40;
    //    float  width  = (BOUNDWIDTH  - IMGWIDTH(image)*4-marX*2)/3;
    float width = BOUNDWIDTH/6;
    float  height  = 100;
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame =  CGRectMake(width*index, 20, width, height);
    btn.tag = index + BTGBUTTON;
    [btn addTarget:self action:@selector(handleBtnAction:) forControlEvents:UIControlEventTouchUpInside];
//    [btn setTitle:title forState:UIControlStateNormal];
//    [btn setImage:image forState:UIControlStateNormal];
//    [btn setTitleColor:Common_TextColor forState:UIControlStateNormal];
//    btn.titleLabel.font = FONT_SIZE(12);
//    btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;//使图片和文字水平居中显示
//    //    UIEdgeInsetsMake(<#CGFloat top#>, <#CGFloat left#>, <#CGFloat bottom#>, <#CGFloat right#>)
//    [btn setTitleEdgeInsets:UIEdgeInsetsMake(btn.imageView.frame.size.height-20 ,-btn.imageView.frame.size.width, 0.0,0.0)];//文字距离上边框的距离增加imageView的高度，距离左边框减少imageView的宽度，距离下边框和右边框距离不变
//    [btn setImageEdgeInsets:UIEdgeInsetsMake( -btn.titleLabel.bounds.size.height-40-8, 0.0,0.0, -btn.titleLabel.bounds.size.width)];//图片距离右边框距离减少图片的宽度，其它不边
    
    
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake((width-40)/2, 0, 40, 40)];
    imageView.image = image;
    [btn addSubview:imageView];
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 50, width, 15)];
    titleLabel.text = title;
    titleLabel.font = FONT_SIZE(12);
    titleLabel.textAlignment  =  NSTextAlignmentCenter;
    titleLabel.textColor = Common_TextColor;
    [btn addSubview:titleLabel];
    
    [self.topView addSubview:btn];
}

-  (UIScrollView *)scroll
{
    if (!_scroll) {
        _scroll = [UIScrollView new];
    }
    return _scroll;
    
}

-  (UIView *)topView
{
    if (!_topView) {
        _topView = [UIView new];
        _topView.backgroundColor = [UIColor whiteColor];
    }
    return _topView;
    
}

-  (UIView *)centerView
{
    if (!_centerView) {
        _centerView = [UIView new];
        _centerView.backgroundColor = [UIColor whiteColor];
    }
    return _centerView;
    
}

-  (UIView *)downView
{
    if (!_downView) {
        _downView = [UIView new];
        _downView.backgroundColor = [UIColor whiteColor];
    }
    return _downView;
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
